package commonUtils.entities;

import lombok.Data;

import java.io.Serializable;

@Data
public class Restful<D> implements Serializable {
    private int code;
    private D data;
    private String msg;

    public Restful() {
    }

    public Restful(int code, D data) {
        this.code = code;
        this.data = data;
    }

    public Restful(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public  Restful(int code, D data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }


    public static <T> Restful<T> success(T data) {
        Restful<T> r = new Restful<T>();
        r.data = data;
        r.code = 1;
        return r;
    }

    public static <T> Restful<T> error(String msg) {
        Restful<T> r = new Restful<T>();
        r.msg = msg;
        r.code = 0;
        return r;
    }

}
